home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / amac44c.zip / RFR005.QM < prev    next >
Text File  |  1992-02-16  |  23KB  |  481 lines

  1. *                               RFR005.QM
  2. *                  Macros To Count Words And Characters
  3. *                        Written By Tom Hogshead
  4. *                       [ See RFRMxx.QM For Use ]
  5. *                                2/16/92
  6. *  Key       Subfile                       Description
  7. * =====  ===============  ====================================================
  8. * @(3)                    Count Words in a File by John Goodman (Use this)
  9. * @(0)                    Count Words in a File (Alternate version of @3)
  10. * @(6)                    Count Words & Characters in File w/COUNT.EXE
  11. * @(4)                    Count Words in a Block  by John Goodman
  12. * @(5)                    Count Characters In A File INCLUDING Spaces
  13. * @(2)                    Count Characters in a File EXCLUDING Spaces
  14. * @(1)                    Count Characters in a Block
  15. *
  16. * @(9)   {e:\up\mis002}   Add Line Numbers  001 to  999 In Col 1
  17. * @(0)   {e:\up\mis002}   Add Line Numbers 0001 to 9999 In Col 1
  18. * @(3)   {e:\up\mis002}   Make File of Numbers 0001 to 9999 Ascending
  19. * @(4)   {e:\up\mis002}   Make File of Numbers 9999 to 0001 Descending
  20. * @(5)   {e:\up\mis002}   Make File of Numbers  001 to  999 Ascending
  21. * @(6)   {e:\up\mis002}   Make File of Numbers  999 to  001 Descending
  22. * @(1)   {e:\up\mis002}   Add Line Numbers 0001 to 9999 In Col 81
  23. * @(2)   {e:\up\mis002}   Remove Previous Line Numbers Made With @1
  24. *
  25. *          {e:\up\RFRM*}--Return To RFRMxx.QM
  26. * (Calibrated) Test File
  27. * (Timing) Results
  28. *
  29. *-- eoi
  30.  
  31.  
  32. * 
  33. * --------------------------------------
  34. * @(0) Macro To Count Words In File
  35. * --------------------------------------
  36. * This macro counts the number of words in a File.  A word is defined
  37. * as a string of characters contained in either the AltWordSet
  38. * separated by a word delimiter.  The number of words in the File equal
  39. * the number of lines in the NUL file after execution.
  40.  
  41. * Test macro using the calibrated file WORD (41 words).
  42.  
  43. * [ Number of WORDS in File ] = [ Number of LINES in temp file ]
  44.  
  45. @0 Macrobegin
  46.         AltWordSet
  47.         UnMarkBlock
  48.         EndLine
  49.         Dropanchor
  50.         StoreScrBuff "c" Return
  51.         BegFile
  52.     LOOP:
  53.         MarkWord
  54.     jfalse 1:
  55.         AppendScrBuff "c" Return
  56.     1:  WordRight
  57.     jtrue LOOP:
  58.         EditFile "NUL" Return Quit
  59.         EditFile Return
  60.         GetScrBuff "c" Return
  61.         UnMarkBlock
  62.         DefaultWordSet
  63.         BegFile
  64.         DelLine
  65.         EndFile
  66. *
  67. * 82 bytes Wed  02-20-1991  16:54:02
  68. * 83 bytes Mon  07-15-1991  11:06:17 (TH @0, changed ! to NUL)
  69. * 45 bytes Wed  08-21-1991  23:55:04 (TH @0)
  70.  
  71.  
  72.  
  73. * 
  74. * ----------------------------------------------------------------------
  75. * @(1) Count Number Of Characters In A Block
  76. * ----------------------------------------------------------------------
  77. * To: Mike Butler, RelayNet, May 4, 1991  15:16:09
  78. * MB> Is there any way to create a macro to count the number of
  79. * MB> characters in a block?
  80.  
  81. * This QEdit macro determines a block's byte size and provides a means
  82. * to calculate the Number of Characters in a block.  Block Byte Size can
  83. * be useful for uploading CompuServe files where upload file descriptions
  84. * are limited to 465 bytes:
  85. *     Block Byte Size = Size of block if it were a file
  86. *     Character Count = (Block Byte Size) minus 2 x (Number of Lines)
  87. * Mark a block.  Block need not be closed.  Block byte size will be shown in
  88. * a window and in front of the last line of a copy of the block.  Press
  89. * <enter> to remove the window from the screen and return to the our
  90. * starting point.  To determine the number of actual characters in a block,
  91. * including spaces between text, subtract 2 x (number of lines in window)
  92. * from (byte size).  The paragraph below with asterisks is 274 bytes, and
  93. * has 277 - 4 x 2 = 269 characters including spaces and asterisks.
  94.  
  95. * NOTE: c:temp and c:dir are temporary files created and deleted from the
  96. * disk.  Rename files and run QMAC if this causes problems.  This macro has
  97. * only been tested with DOS 3.3.  SaveFile is used rather than WriteBlock
  98. * in case c:temp and c:dir exist before running.
  99.  
  100. @1 Macrobegin
  101.         Editfile "c:temp" Return        * Load temp file
  102.         killfile Quit                   * Kill/quit c:temp
  103.         EditFile Return                 * Load empty c:temp
  104.         Copyblock                       * Copy block to temp file
  105.         EndFile DelLine                 * Delete extra blank line
  106.         Savefile                        * Save temp file to get size
  107.         DOS "Dir " Currentfilename      * Get  DIR list of c:temp
  108.         ">C:dir" Return Return          * Save DIR list of c:temp
  109.         Editfile "C:dir" Return         * Load DIR list
  110.         Gotoline "5" Return             * CursorDown to c:temp line
  111.         Wordright Markword Copy         * Copy size to scrap
  112.         Killfile Quit                   * Kill/quit c:dir
  113.         Editfile "c:temp" Return        * Load c:temp
  114.         Killfile                        * Kill it
  115.         Endfile Begline                 *
  116.         "Block size=" Paste             * Paste block size at bottom
  117.         Makebotofscreen                 * Re-position
  118.         Pause                           * Press <enter> to remove block size
  119.         Quit                            * Character Count = Block Size
  120.                                         *     minus 2 x Number of Lines
  121. * 114 bytes Sat  05-04-1991  15:15:25
  122.  
  123.  
  124. * 
  125. * ----------------------------------------------------------------------
  126. * @(2) Count Number Of Characters In A File EXCLUDING Spaces
  127. * ----------------------------------------------------------------------
  128. * This macro counts the number of characters in a file EXCLUDING
  129. * spaces.  @5 counts the number of characters in a file INCLUDING
  130. * spaces.  The number of characters in a file is calculated by
  131. * subtracting 2 x number of lines in file c:temp from reported byte
  132. * size after macro execution.
  133.  
  134.  
  135. @2 Macrobegin
  136.         UnMarkBlock                     * Un-mark all blocks
  137.         BegFile Markblockbegin          * Mark File
  138.         EndFile Markblockend            *
  139.         Editfile "c:temp" Return        * Load empty c:temp
  140.         Killfile Quit                   * Kill/quit c:temp
  141.         Editfile Return                 * Load empty temp file
  142.         Copyblock Unmarkblock           * Copy File to temp file
  143.         Findreplace " " Return          * Replace all single spaces
  144.         DelLine Return "GN" Return      * With Blanks, globally
  145.  DELBLANKLINES:                         *
  146.         Begfile                         * Get to begin of file
  147.  CHK4BLANK:                             *
  148.         Endline Begline                 * Check if line has text
  149.         Jtrue  NOTBLANK:                * If so, go to NOTBLANK
  150.         Delline                         * Or line is blank, delete it
  151.         Jtrue CHK4BLANK:                * Go check next line
  152.  NOTBLANK:                              *
  153.         Endpara                         *ELSE  Move to paragraph end
  154.         Cursordown                      * Move down to next line
  155.         Jtrue CHK4BLANK:                * If not eof, check again
  156.  GETCOUNT:                              *
  157.         Savefile                        * Save temp file to get size
  158.         DOS "DIR " Currentfilename      * Get  DIR list of c:temp
  159.         ">C:dir" Return Return          * Save DIR list of c:dir
  160.         Editfile "C:dir" Return         * Load DIR list
  161.         Gotoline "5" Return             * Cursordown to c:temp line
  162.         Wordright Markword Copy         * Copy size to scrap
  163.         Killfile Quit                   * Kill/quit c:dir
  164.         Editfile  "c:temp" Return       * Load compressed c:temp
  165.         Killfile                        * Kill c:temp disk copy
  166.         Begline "Byte size=" Paste      * Paste byte size at bottom
  167.         Makebotofscreen                 * Re-position
  168.         Pause                           * Press <enter> to remove window
  169.         Quit                            * Character Count = Byte Size
  170.                                         *     minus 2 x Number of Lines
  171. * 92 bytes Wed  02-20-1991  17:02:29
  172. * 141 bytes Sat  05-04-1991  15:38:07 changed temp file names, added pause
  173. *                                     corrected gotoline "5"
  174.  
  175. * 
  176. * ---------------------------------------------
  177. * @(3) Count Words in File
  178. *      Alternate version of @0 by John Goodman
  179. * ---------------------------------------------
  180. * This macro will count the number of words in the current file.  A
  181. * word is considered to be a sequence of one or more characters in
  182. * the AltWordSet delimited by at least one character that is not in
  183. * the AltWordSet (this definition should suffice for most
  184. * applications).  The number of words in the file is displayed in a
  185. * separate window after they have been counted.  When the Enter key
  186. * is pressed, the word count display will be removed and the cursor
  187. * will be positioned at the top of the original file. The macro
  188. * should work consistently regardless of mode toggle or QConfig
  189. * settings and will not change the edit status of the original
  190. * file.  The macro does, however, set the word character set to
  191. * DefaultWordSet at the end of the macro.
  192. *
  193. @3  MacroBegin
  194.     AltWordSet          * Use alternate word character set
  195.     UnmarkBlock BegFile * Remove blocks and start at top
  196.     OneWindow           * Remove any windows
  197.     EditFile            * Use the NUL file for counting
  198.       "NUL" Return
  199.     Quit                * Make sure NUL file is empty
  200.     HorizontalWindow    * Create window for counting
  201.     EditFile Return     * Re-edit the NUL file
  202.     DropAnchor          * Start a block
  203.     "0123456789"        * Type digits 0-9
  204.     Copy BegLine        * Make six copies of digits line
  205.     Paste 6
  206.     MarkCharacter       * Copy the digits w/out EOL char
  207.     EndLine Copy
  208.     UnmarkBlock
  209.     PrevWindow          * Return to original file
  210.  MAINLOOP:              * Loop for each word in file
  211.     MarkWord            * Test if a word at cursor position
  212.     JFalse NEXTWORD:    * If not, skip to next word
  213.     NextWindow          * Go to counting window
  214.     EndFile BegLine     * Go to ones digit position
  215.  INCRLOOP:
  216.     DelCh               * Delete (increment) the current digit
  217.     EndLine             * Test if any digits remaining
  218.  JTrue INCRDONE:
  219.     Paste               * Re-paste the 0-9 string
  220.     UnmarkBlock
  221.     CursorUp            * Go to up next significant digit
  222.  Jump INCRLOOP:         * Increment next significant digit
  223.  INCRDONE:
  224.     PrevWindow          * Return to original file
  225.  NEXTWORD:
  226.     WordRight           * Go to next word right
  227.  JTrue MAINLOOP:        * If no words to right, display count
  228.     BegFile             * Return to beginning of original file
  229.     NextWindow          * Go to count window
  230.     BegFile CursorRight * Go to top of 2nd column
  231.     MarkColumn          * Delete all but column 1
  232.     EndLine PageDown
  233.     DeleteBlock
  234.     JOINLOOP:           * Join column 1 into a single line
  235.       CursorUp
  236.       JFalse PROMPT:
  237.       JoinLine
  238.     Jump JOINLOOP:
  239.  PROMPT:
  240.     EndLine             * Go to end of count and display prompt
  241.     " Words... Press <Enter> to Continue"
  242.     Pause               * Wait for user to press Enter
  243.     Quit CloseWindow    * Delete the NUL file and close window
  244.     DefaultWordSet      * Reset default word set characters
  245. *
  246. * 167 bytes Fri  08-23-1991  21:29:35 (JG @3)
  247.  
  248. * 
  249. * ---------------------------------
  250. * @(4) Count Words in Marked Block
  251. *      Written by John Goodman
  252. * ---------------------------------
  253. * This macro will count the number of words in the currently marked
  254. * block. Any type of block may be used and both block end points
  255. * need not be set. A word is considered to be a sequence of one or
  256. * more characters in the AltWordSet delimited by at least one
  257. * character that is not in the AltWordSet (this definition should
  258. * suffice for most applications).  The number of words in the block
  259. * is displayed in a separate window after they have been counted.
  260. * When the Enter key is pressed, the word count display will be
  261. * removed and the cursor will be positioned at its original
  262. * location in the file (the original block will be unmarked). The
  263. * macro should work consistently regardless of mode toggle or
  264. * QConfig settings and will not change the edit status of the
  265. * original file.  The macro does, however, set the word character
  266. * set to DefaultWordSet at the end of the macro.
  267. *
  268. @4  MacroBegin
  269.     AltWordSet          * Use alternate word character set
  270.     OneWindow           * Remove any windows
  271.     EditFile            * Use the NUL file for counting
  272.       "NUL" Return
  273.     Quit                * Make sure NUL file is empty
  274.     HorizontalWindow    * Create window for counting
  275.     EditFile Return     * Re-edit the NUL file
  276.     CopyBlock           * Copy the block of text to NUL file
  277.     JFalse END:         * If no block, exit
  278.     UnmarkBlock         * Unmark the block
  279.     SplitLine           * Put blank line at top
  280.     DropAnchor          * Start a block
  281.     "0123456789"        * Type digits 0-9
  282.     Copy BegLine        * Make six copies of digits line
  283.     Paste 6
  284.     MarkCharacter       * Copy the digits w/out EOL char
  285.     EndLine Copy
  286.     UnmarkBlock
  287.     BegFile             * Go to beginning of text
  288.     CursorDown 7
  289.  MAINLOOP:              * Loop for each word in file
  290.     DeleteBlock         * Delete the last word processed
  291.     MarkWord            * Test if a word at cursor position
  292.     JFalse NEXTWORD:    * If not, skip to next word
  293.     CursorUp BegLine    * Go to ones digit position
  294.  INCRLOOP:
  295.     DelCh               * Delete (increment) the current digit
  296.     EndLine             * Test if any digits remaining
  297.  JTrue INCRDONE:
  298.     Paste               * Re-paste the 0-9 string
  299.     UnmarkBlock
  300.     CursorUp            * Go to up next significant digit
  301.  Jump INCRLOOP:         * Increment next significant digit
  302.  INCRDONE:
  303.     BegFile             * Return to beginning of text
  304.     CursorDown CursorDown  * Many cursordowns instead of displaying
  305.     CursorDown CursorDown  * RepeatCmd prompt box many times
  306.     CursorDown CursorDown
  307.     CursorDown
  308.  NEXTWORD:
  309.     MarkCharacter       * Block last word processed to delete it
  310.     WordRight           * Go to next word right
  311.  JTrue MAINLOOP:        * If no words to right, display count
  312.     UnmarkBlock
  313.     BegFile CursorRight * Go to top of 2nd column
  314.     MarkColumn          * Delete all but column 1
  315.     EndLine PageDown
  316.     DeleteBlock
  317.     JOINLOOP:           * Join column 1 into a single line
  318.       CursorUp
  319.       JFalse PROMPT:
  320.       JoinLine
  321.     Jump JOINLOOP:
  322.  PROMPT:
  323.     EndLine             * Go to end of count and display prompt
  324.     " Words... Press <Enter> to Continue"
  325.     Pause               * Wait for user to press Enter
  326.  END:
  327.     Quit CloseWindow    * Delete the NUL file and close window
  328.     DefaultWordSet      * Reset default word set characters
  329. *
  330. * 183 bytes Fri  08-23-1991  17:45:40 (JG @4)
  331.  
  332.  
  333. * (Calibrated) Test File, 41 Words with @0 and @3
  334.  
  335. * ┌────────────────────────────── WORD ─────────────────────────────────────┐
  336. * │  1 2  3                                                                 │
  337. * │                                                                         │
  338. * │ ! @ # $ % ^ & * ' ( ) + | - = \ , . / ; ' [ ] < > ? : " { }             │
  339. * │                                                                         │
  340. * │ !@#$%^&*'()+|-=\,./;'[]<>?:"{}                                          │
  341. * │                                                                         │
  342. * │  4   5   6                                                              │
  343. * │                  126__Characters 41_Words(W/@0) 41_Words(W/@3) 7 8 9 aa │
  344. * │                                                                         │
  345. * │ __ Characters                                                           │
  346. * └─────────────────────────────────────────────────────────────────────────┘
  347.  
  348. * 
  349. * ----------------------------------------------------------------------
  350. * @(5) Count Number Of Characters In A File INCLUDING Spaces
  351. * ----------------------------------------------------------------------
  352. * This macro counts the number of characters in a file INCLUDING
  353. * spaces.  @2 counts the number of characters in a file EXCLUDING
  354. * spaces.  The number of characters in a file is calculated by
  355. * subtracting 2 x number of lines in file c:temp from reported byte
  356. * size after macro execution.
  357.  
  358. @5 Macrobegin
  359.         UnMarkBlock                     * Un-mark all blocks
  360.         BegFile Markblockbegin          * Mark File
  361.         EndFile Markblockend            *
  362.         Editfile "c:temp" Return        * Load empty c:temp
  363.         Killfile Quit                   * Kill/quit c:temp
  364.         Editfile Return                 * Load empty temp file
  365.         Copyblock Unmarkblock           * Copy File to temp file
  366. *         Findreplace " " Return          * Replace all single spaces
  367. *         DelLine Return "GN" Return      * With Blanks, globally
  368.  DELBLANKLINES:                         *
  369.         Begfile                         * Get to begin of file
  370.  CHK4BLANK:                             *
  371.         Endline Begline                 * Check if line has text
  372.         Jtrue  NOTBLANK:                * If so, go to NOTBLANK
  373.         Delline                         * Or line is blank, delete it
  374.         Jtrue CHK4BLANK:                * Go check next line
  375.  NOTBLANK:                              *
  376.         Endpara                         *ELSE  Move to paragraph end
  377.         Cursordown                      * Move down to next line
  378.         Jtrue CHK4BLANK:                * If not eof, check again
  379.  GETCOUNT:                              *
  380.         Savefile                        * Save temp file to get size
  381.         DOS "DIR " Currentfilename      * Get  DIR list of c:temp
  382.         ">C:dir" Return Return          * Save DIR list of c:dir
  383.         Editfile "C:dir" Return         * Load DIR list
  384.         Gotoline "5" Return             * Cursordown to c:temp line
  385.         Wordright Markword Copy         * Copy size to scrap
  386.         Killfile Quit                   * Kill/quit c:dir
  387.         Editfile  "c:temp" Return       * Load compressed c:temp
  388.         Killfile                        * Kill c:temp disk copy
  389.         Begline "Byte size=" Paste      * Paste byte size at bottom
  390.         Makebotofscreen                 * Re-position
  391.         Pause                           * Press <enter> to remove window
  392.         Quit                            * Character Count = Byte Size
  393.                                         *     minus 2 x Number of Lines
  394. * 141 bytes Sat  05-04-1991  15:38:07 (TH @2)
  395. * 130 bytes Wed  08-28-1991  00:13:49 (TH @5)
  396.  
  397. * 
  398. * ----------------------------------------------------------------------
  399. * @(6) Count Words and Characters in File Using COUNT.EXE
  400. * ----------------------------------------------------------------------
  401. * This macro counts the number of words and characters in the file
  402. * currently being edited using COUNT.EXE written by Robert Kiesling.
  403. * COUNT.EXE can be found on Exec-PC as COUNT2.ZIP.
  404.  
  405. @6 macrobegin
  406.         savefile
  407.         DOS "count " currentfilename return
  408. *
  409. * 20 bytes Thu  08-29-1991  08:58:12 (TH @6)
  410.  
  411.  
  412. *          (Timing) Results of First 1,000 Words of QEDIT.DOC
  413. *         ───────────────────────────────────────────────────-
  414. *           Letters   Words   Chars  Lines  Blank   Seconds
  415. *           --------  -----   -----  -----  -----   -------
  416. * COUNT.EXE           1004    7294    175             1.43
  417. * RWC.EXE     6940    1002            175     48      2.36
  418. * WC.EXE              1008    7119    175             2.80
  419. * @5 (TH)                     6944                    4.3 - spaces counted
  420. * @2 (TH)                     5571                    6.2 - spaces not counted
  421. * @3 (JG)             1000                           41.6 <- Best Macro to use
  422. * @4 (JG)             1000                          105.4
  423. * @0 (TH)             1000                          108.2
  424.  
  425. *    (JG) John Goodman, author
  426.  
  427. * The above timing results are reported for the first 1,000 words of
  428. * the QEdit Reference Manual, QEDIT.DOC, v2.1 dated February 1990, 175
  429. * lines, included with the Shareware version.  The 1,000th word is
  430. * 'use' on line 175.  This 1,000 word portion of QEDIT.DOC is included
  431. * in AMACxx.ZIP as file 'word1k'.  Timing measurements reported to two
  432. * decimal places were measured with TIMER.EXE dated 11/10/85.  Timing
  433. * measurements reported to one decimal place were measured using a
  434. * stopwatch.
  435.  
  436. * As can be seen from these timing results, COUNT.EXE appears to be the
  437. * fastest and most versatile program.  It can be found on Exec-PC as
  438. * COUNT2.ZIP.  The fact that COUNT.EXE counts 4 more words than @0, @3
  439. * or @4 must be attributable to different definitions of 'words'.  Of
  440. * the macros to count words, John Goodman's @3 is by far the fastest
  441. * and should be the macro of choice for this purpose.  Thanks John for
  442. * this superb job of macro programming.
  443.  
  444. * Although the character counts are 'close' comparing COUNT.EXE,
  445. * WC.EXE, and @5, these differences must also be attributed to
  446. * different definitions of 'characters' and/or counting techniques:
  447.  
  448. *         @5: 7204 bytes - 2 x 130 lines = 6944 chars
  449. *         @3: 5831 bytes - 2 x 130 lines = 5571 chars
  450.  
  451. * COUNT.EXE appears the program to use based on speed.  Preferred use
  452. * of @2 or @5 depends user on requirements.  Note COUNT.EXE byte count
  453. * of characters is 175 more than with WC.EXE possibly because COUNT.EXE
  454. * counts the 175 eol characters inserted by QEdit and WC.EXE does not.
  455. * COUNT.EXE character count is the byte size of the file counted.
  456.  
  457. * As a point of interest, following is the timed output using COUNT.EXE
  458. * on the file QEDIT.DOC:
  459.  
  460. *          Volume in drive E is Seagate 1
  461. *          Directory of  E:\QE
  462.  
  463. *         QEDIT    DOC   244279   4-03-90   2:10a
  464. *                 1 File(s)   3393536 bytes free
  465.  
  466. * Executing E:\COMMAND.COM/c count E:\QE\QEDIT.DOC
  467. * Count (c)1987 Robert Kiesling.  All rights reserved
  468.  
  469. * Counting E:\QE\QEDIT.DOC
  470. * Characters:     244279
  471. * Words:          32569
  472. * Lines:          6253
  473.  
  474. * [E:\COMMAND.COM/c count E:\QE\QEDIT.DOC]
  475.  
  476. * Start: 08/28/1991 - 02:53:42.44
  477. * Stop:  08/28/1991 - 02:54:03.47
  478.  
  479. * Elapsed time: 0 hours, 0 minutes, 21.03 seconds.
  480.  
  481.